package com.ali.juejin.base

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.ali.juejin.ui.activity.LoginActivity
import com.blankj.utilcode.util.SPUtils

open class BaseModelActivity: AppCompatActivity() {

    private val sp by lazy { SPUtils.getInstance() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
        initData()
    }


    open protected fun initView(){

    }

    open protected fun initData(){

    }

    // 返回上一个activity
    protected fun onBack(){
        finish()
    }

    // 未登录则跳转到登录页
    fun interceptLogin():Boolean{
        val token = sp.getString("token","")
        if(token.isNullOrEmpty()){
            startActivity(Intent(this, LoginActivity::class.java))
            return false
        }
        return true
    }
}